/**
 * 初始化JS文件
 * 
 * @author		布衣才子
 * @date		2012-10-01
 * @email		work.jerryliu@gmail.com
 * @qq			394969553
 * @version		v1.0
 * @copyright	copyright 2012-2014	YeeYi.com All Rights Reserved	
 */


/**
 * 
 * 服务器访问地址
 */
var apiHost = "http://www.yeeyi.com/bbs/forum.php?jsoncallback=?&mod=mobile";

/**
 * 网络访问函数
 * @param {Object} url	请求的网络地址
 * @param {Object} callback	回调函数
 */
function xmlHttp(url,callback){
	if(url == ''){
		uexWindow.alert('参数错误','请求地址不能为空！','返回');
	}else{
		var platform = getLocalStorge('platform');
		url = url + "&pf="+platform;
		$.getJSON(url,callback);
	}
}

/**
 * foot部分菜单切换函数
 * @param {Object} type
 */
function windowOpen(type){
	if(type == 'news'){
		$('#headtitle img').attr('src','css/images/news_title.png');
		$('.zhengchang').removeClass('anxia');
		$('#8_cid').addClass('anxia');
		$('#subtitle').show();
		$('#loginBtn').hide();
		changeFooterBg(type);
		zy_con("content", "index_content.html", 0, $$("header").offsetHeight);
		setTimeout(function(){
			zy_resize("content",0,$$("header").offsetHeight);
		},1);
		getNotice();
	}else if(type == 'bbs'){
		$('#subtitle').hide();
		$('#headtitle img').attr('src','css/images/bbs_title.png');
		var uid = getLocalStorge('uid');
		if(!uid){
			$('').text('');
		}else{
			$('').text('');
		}
		$('#loginBtn').show();
		changeFooterBg(type);
		zy_con("content", "about.html", 0, $$("header").offsetHeight);
		setTimeout(function(){
			zy_resize("content",0,$$("header").offsetHeight);
		},1);
		getNotice();
	}else if(type == 'activity'){
		$('#subtitle').hide();
		$('#headtitle img').attr('src','css/images/act_title.png');
		$('#loginBtn').hide();
		changeFooterBg(type);
		zy_con("content", "activity_content.html", 0, $$("header").offsetHeight);
		setTimeout(function(){
			zy_resize("content",0,$$("header").offsetHeight);
		},1);
		getNotice();
	}else if(type == 'pic'){
		$('#subtitle').hide();
		$('#headtitle img').attr('src','css/images/act_pic.png');
		$('#loginBtn').hide();
		changeFooterBg(type);
		zy_con("content", "pic_list.html", 0, $$("header").offsetHeight);
		setTimeout(function(){
			zy_resize("content",0,$$("header").offsetHeight);
		},1);
		getNotice();
	}else if(type == 'space'){
		var uid = getLocalStorge('uid');
		if(!uid){
			localStorage.setItem('confirmType','login');
			var confirmButtom = new Array();
			confirmButtom[0] = '确 定';
			confirmButtom[1] = '返 回';
			uexWindow.confirm('提示','请先登录，再进行操作！',confirmButtom);
		}else{
			$('#subtitle').hide();
		    $('#headtitle img').attr('src','css/images/home_title.png');
			$('#tips').hide();
		    $('#loginBtn').hide();
			changeFooterBg(type);
			zy_con("content", "home_content.html", 0, $$("header").offsetHeight);
			setTimeout(function(){
				zy_resize("content",0,$$("header").offsetHeight);
			},1);
		}
	}
}

function checkHtml5(){
	if(!window.localStorge){
		uexWindow.alert('提示','您的手机浏览器可能不支持html5,请下载最新浏览器或访问Wap版亿忆网！');
	}
}

/**
 * 显示默认论坛窗口，在清除缓存和登录登录后调用的方法
 */
function defaultWindow(){
	    $('#headtitle img').attr('src','css/images/bbs_title.png');
		$('#loginBtn div').text('登录');
		$('#loginBtn').show();
		changeFooterBg('bbs');
		zy_con("content", "forum_index.html", 0, $$("header").offsetHeight);
}

/**
 * 初始化获取用户短信和提醒
 */
function getNotice(){
	var uid = getLocalStorge('uid');
	if(uid){
		var url = apiHost + '&ac=init&uid='+uid;
		xmlHttp(url,showNotice);
	}
}

/**
 * 显示用户短信和提醒的数量
 * @param {Object} data
 */
function showNotice(data){
	var code = data.code;
	if(code == '404'){
	}else if(code == '0'){
	}else{
		code = parseInt(code);
		$('#tips').text(code).show();
	}
}

/**
 * 新闻二级菜单操作函数
 * @param {Object} id
 */
function changeSubTitle(id){
	$('.zhengchang').removeClass('anxia');
	$('#'+id+'_cid').addClass('anxia');
	uexWindow.evaluatePopoverScript('','content','changeNewsList('+id+')');
}

/**
 * 改变底部菜单背景
 * @param {Object} type
 */
function changeFooterBg(type){
	$('#footer .tab-padding').removeClass('footerActive');
	$('#footer .'+type).addClass('footerActive');
}

/**
 * confirm控件监控函数
 * @param {Object} opId
 * @param {Object} dataType
 * @param {Object} data
 */
function confirmSuccess(opId,dataType,data){
	var ctype = getLocalStorge('confirmType');
	if(data == 0){
		if(ctype == 'exit'){
			uexWidgetOne.exit();
		}else{
			uexWindow.open('login','0','login.html','1','100%','100%','0');
		}
	}
}

/**
 * 隐藏登录按钮
 */
/*
function hideLogin(){
	$('#loginBtn div').text('菜单');
	getNotice();
}*/

/**
 * 登录页面转向
 */
function gotoLogin(){
	localStorage.setItem('returnType','forum');
	uexWindow.open('login','0','login.html','1','100%','100%','0');
}

function showMenu(){
	var uid = getLocalStorge('uid');
	if(!uid){
		gotoLogin();
	}else{
		uexWindow.evaluatePopoverScript('','content','showMenu()');
	}
}


/**
 * HTML5 localStorge.getItem 函数的封装
 * @param {Object} key
 */
function getLocalStorge(key){
	var item = localStorage.getItem(key);
	if(item=='' || item=='0' || item==null || typeof(item)=="undefined"){
		return false;
	}else{
		return item;
	}
}



